//
//  LGRecycleViewController.m
//  LuxuryGoods
//
//  Created by 刘星辰 on 2018/5/22.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "LGRecycleViewController.h"
#import "LGCommodityInfoView.h"
#import "LGImageManagerIO.h"
#import "LGCommodityProtocolView.h"
#import "UIViewController+Album.h"
#import "LGHintViewController.h"

@interface LGRecycleViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIButton *recycleBtn;

@end

@implementation LGRecycleViewController

//- (void)viewDidLayoutSubviews
//{
//    [super viewDidLayoutSubviews];
//    LGCommodityInfoView * view = (LGCommodityInfoView *)[self.view viewWithTag:99];
//    [view.desTextView layoutSubviews];
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"商品信息";
    [self addNavRightBtn];
    
    [self addCommodityInfoView];

    [self.recycleBtn setCornerRadius:self. recycleBtn.height / 2.0];
    UIImage *image = [LGImageManagerIO createGradualColorImage:self.recycleBtn.size startColor:LOW_COLOR endColor:HIGH_COLOR];
    [self.recycleBtn setBackgroundImage:image forState:UIControlStateNormal];

    [self addProtocolView];
}

- (void)addProtocolView
{
    LGCommodityProtocolView *view = [LGCommodityProtocolView createFromXib];
    [self.view addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.recycleBtn.superview.mas_top).offset(0);
        make.width.offset(SCREEN_WIDTH);
        make.height.offset(30);
        make.left.offset(0);
    }];
}

- (void)addCommodityInfoView
{
    LGCommodityInfoView *view = [LGCommodityInfoView createFromXib];
    CGSize size = [view systemLayoutSizeFittingSize:CGSizeMake(SCREEN_WIDTH, CGFLOAT_MIN)];
    view.size = CGSizeMake(SCREEN_WIDTH, size.height);
    [self.scrollView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(0);
        make.width.offset(SCREEN_WIDTH);
        make.height.offset(size.height);
        make.bottom.offset(0);
    }];
    WeakObj(self)
    //浏览照片的流程
    view.checkPhoto = ^{
        [selfWeak gotoRecycleWebView];
    };
    
    //选择照片
    view.choosePhoto = ^(LGCommodityInfoView *view) {
        [selfWeak pickerManyImageCount:12 - view.dataArray.count handle:^(NSArray<PHAsset *> *images) {
            [view addPhotoAndRefreshUIWith:images];
    
        }];
    };
    
    //view
    view.browsePhoto = ^(LGCommodityInfoView *view, NSInteger index) {
    
        [selfWeak gotoSelectedAssets:view.dataArray index:index];
    };
}

#pragma mark nav上右侧按钮
- (void)addNavRightBtn
{
    UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"回收流程" forState:UIControlStateNormal];
    button.titleLabel.font =  FONT(15);
    [button setTitleColor:TEXT_COLOR_1 forState:UIControlStateNormal];
    [button addTarget:self action:@selector(gotoRecycleWebView) forControlEvents:UIControlEventTouchUpInside];
    [button sizeToFit];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    
}
- (IBAction)recycleAction:(id)sender
{
    LGHintViewController *vc = [LGHintViewController createFromXib];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)gotoRecycleWebView
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
